<?php

require 'module/base/wmsHandler.class.php';
class pa_store {

    public function execute() {

        if (isset($_REQUEST['operFlg'])) {

            switch($_REQUEST['operFlg']) {

                case 1:
                    $this->storeList();  //仓库列表
                    break;

                case 2:
                    $this->storeAdd();  //添加仓库
                    break;

                case 3:
                    $this->storeEdit();  //编辑仓库
                    break;

                case 4:
                    $this->storeRegionAdd();  //添加、编辑仓库区域
                    break;

                case 5:
                    $this->storeShelfList();  //仓库库位列表
                    break;

                case 6:
                    $this->storeShelfAdd();  //添加仓库库位
                    break;

                case 7:
                    $this->storeShelfEdit();  //编辑仓库库位
                    break;

                case 8:
                    $this->shelfBatch();  //批量添加库位
                    break;

                case 9:
                    $this->shelfExport();  //导出仓库库位信息
                    break;

                case 10:
                    $this->shelfImport();  //显示导入模板
                    break;

                case 11:
                    $this->importShelf();  //导入仓库库位
                    break;

                case 12:
                    $this->goodsUp();  //货品上架
                    break;

                case 13:
                    $this->shelfManage();  //货位管理
                    break;

                case 14:
                    $this->storeshelfExport();  //导出仓库货位列表信息
                    break;

                case 15:
                    $this->dailyManage();       //日常管理
                    break;

            }

        }

    }

    //仓库列表
    private function storeList() {

        global $G_PGLOB;

        $G_PGLOB->smarty->assign( 'EDIT_PERMISSION' , $G_PGLOB->has_permission(6007) );
        $G_PGLOB->smarty->display('wms/storeList.tpl');

    }

    //添加仓库
    private function storeAdd() {

        global $G_PGLOB;

        //查询省份信息
        $provinceInfo = $G_PGLOB->DBCA->stmt_query( 'SELECT * FROM sys_region WHERE region_level=?' , 'i' , 1 );

        //查询出现有的仓库ID最大值
        $search_max_id = $G_PGLOB->DBCA->stmt_query( 'SELECT MAX(storeID) storeID FROM wms_store');

        $store_no = empty($search_max_id) || empty($search_max_id[0]->storeID) ? 0 : $search_max_id[0]->storeID;

        //组装仓库编号
        $store_no =  'MR' . str_pad( ($store_no+1) , 3 , '0' , STR_PAD_LEFT );

        $G_PGLOB->smarty->assign( 'store_no' , $store_no );
        $G_PGLOB->smarty->assign_by_ref( 'provinceList' , $provinceInfo );
        $G_PGLOB->smarty->display('wms/storeAdd.tpl');

    }

    //编辑仓库
    private function storeEdit() {

        global $G_PGLOB;

        //实例化公共类
        $commHandler = new commHandler( $G_PGLOB->DBCA );

        //接收仓库ID
        $storeID = isset($_REQUEST['storeID'])? $_REQUEST['storeID'] : '';

        if( empty($storeID) ){

            $G_PGLOB->smarty->assign('msg','参数错误，请与管理员联系');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();

        }

        //组装查询条件数组
        $search_arr = array(
            "storeID"=>$storeID,
        );

        //查询
        $result = $commHandler->search( $search_arr , 'wms_store' );

        if( empty( $result ) ){

            $G_PGLOB->smarty->assign('msg','没有找到相关仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();

        }

        foreach ( $result as &$value ){

            //分隔电话号码
            if( !empty($value->phone) ){

                $phone_array = explode( '-' ,  $value->phone);

                $value->p1 = isset($phone_array[0])?$phone_array[0]:'';
                $value->p2 = isset($phone_array[1])?$phone_array[1]:'';
                $value->p3 = isset($phone_array[2])?$phone_array[2]:'';

            }

        }

        //查询省份信息
        $provinceInfo = $G_PGLOB->DBCA->stmt_query( 'SELECT * FROM sys_region WHERE region_level=?' , 'i' , 1 );

        //如果存在城市ID，则查询吃该城市所属省份下所有的城市
        if( $result[0]->cityID ){

            $cityList = $G_PGLOB->DBCA->stmt_query( 'SELECT * FROM sys_region WHERE parentID=? ' , 'i' , $result[0]->provinceID );
            $G_PGLOB->smarty->assign_by_ref( 'cityList' , $cityList );

        }

        //如果存在区ID，则查询吃该区所属城市下所有的区
        if( $result[0]->regionID ){

            $regionList = $G_PGLOB->DBCA->stmt_query( 'SELECT * FROM sys_region WHERE parentID=? ' , 'i' , $result[0]->cityID );
            $G_PGLOB->smarty->assign_by_ref( 'regionList' , $regionList );

        }

        $G_PGLOB->smarty->assign_by_ref( 'provinceList' , $provinceInfo );
        $G_PGLOB->smarty->assign_by_ref( 'store' , $result[0] );
        $G_PGLOB->smarty->assign('storeID' , $storeID);
        $G_PGLOB->smarty->display('wms/storeAdd.tpl');

    }

    //编辑/添加 仓库区域
    private function storeRegionAdd(){

        global $G_PGLOB;

        //接收仓库ID
        $storeID = isset($_REQUEST['storeID'])? $_REQUEST['storeID'] : '';

        if( empty($storeID) ){

            $G_PGLOB->smarty->assign('msg','参数错误，请与管理员联系');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();

        }

        //实例化公共类
        $commHandler = new commHandler( $G_PGLOB->DBCA );

        //查询仓库信息，判断是否存在
        $searchArr = array('storeID'=>$storeID);
        $store = $commHandler->search($searchArr,'wms_store');

        if( empty($store) ){

            $G_PGLOB->smarty->assign('msg','没有找到该仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();

        }

        //查询省份信息
        $provinceSearch = array('region_level'=>1);
        $province       = $commHandler->search($provinceSearch,'sys_region');

        //查询区域
        $sql = 'SELECT * FROM wms_store_region WHERE storeID=?';
        $search_result = $G_PGLOB->DBCA->stmt_query($sql , 'i' , $storeID );

        //省份数组
        $provinceArr = array();
        $provinceList = '';

        //城市数组
        $cityArr = array();
        $cityList = '';

        //区域数组
        $regionArr = array();
        $regionList = '';

        if( $search_result ){

            foreach ( $search_result as $value ){

                if( $value->levelFlg == 1 ){

                    $provinceArr[] = $value->regionID;

                }elseif ( $value->levelFlg == 2 ){

                    $cityArr[] = $value->regionID;

                }elseif ( $value->levelFlg == 3 ){

                    $regionArr[] = $value->regionID;

                }

            }

            if( !empty($provinceArr) ){
                $provinceList = $this->matchList($provinceArr);
            }

            if( !empty($cityArr) ){
                $cityList = $this->matchList($cityArr);
            }

            if( !empty($regionArr) ){
                $regionList = $this->matchList($regionArr);
            }

        }

        if( !empty($provinceList) || !empty($cityList) || !empty($regionList)){
            $G_PGLOB->smarty->assign('editFlg' , 1);
        }else{
            $G_PGLOB->smarty->assign('editFlg' , 0);
        }

        $G_PGLOB->smarty->assign('storeName' , $store[0]->storeName);
        $G_PGLOB->smarty->assign('provinceList' , $provinceList);
        $G_PGLOB->smarty->assign('cityList' , $cityList);
        $G_PGLOB->smarty->assign('regionList' , $regionList);
        $G_PGLOB->smarty->assign_by_ref('province' , $province);
        $G_PGLOB->smarty->assign('storeID' , $storeID);
        $G_PGLOB->smarty->display('wms/storeRegionAdd.tpl');

    }


    //组装城市字符串
    private function matchList( $params ){

        global $G_PGLOB;

        $html = '';

        $commHandler = new commHandler( $G_PGLOB->DBCA );

        if( !is_array($params) || empty($params) )
            return null;

        foreach ( $params as $key=>$value ){

            //组装查询条件数组
            $search_arr = array(
                "id"=>$value
            );

            //查询出该区域ID的信息（调用公共方法）
            $search = $commHandler->search( $search_arr , 'sys_region' );

            if( ($key+1) % 10 == 0 ){
                $html .= '<input type="checkbox" checked  name="regions" id="' . $value . '" value="' . $value . '">' . $search[0]->name  . '<br>';
            }else{
                $html .= '<input type="checkbox" checked  name="regions" id="' . $value . '" value="' . $value . '">' . $search[0]->name . '&nbsp;';
            }

        }

        return 	$html;

    }

    //库位列表
    function storeShelfList(){

        global $G_PGLOB;

        //实例化公共类
        $commHandler = new commHandler($G_PGLOB->DBCA);

        //接收仓库ID
        $storeID = isset($_REQUEST['storeID'])? $_REQUEST['storeID'] : '';

        //查询仓库信息
        $storeInfo = array('storeID'=>$storeID);
        $result = $commHandler->search($storeInfo,'wms_store');

        if( empty($result) ){
            $G_PGLOB->smarty->assign('msg','没有找到该仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();
        }

        $G_PGLOB->smarty->assign('storeName',$result[0]->storeName);
        $G_PGLOB->smarty->assign('storeID',$storeID);
        $G_PGLOB->smarty->display('wms/storeShelfList.tpl');

    }

    //添加仓库货位
    function storeShelfAdd(){

        global $G_PGLOB;

        //获取仓库列表
        $result_store = $G_PGLOB->DBCA->stmt_query('SELECT storeID,storeName FROM wms_store');

        if( empty($result_store) ){
            $G_PGLOB->smarty->assign('msg','没有找到仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();
        }

        $G_PGLOB->smarty->assign_by_ref('store_array',$result_store);
        $G_PGLOB->smarty->display('wms/storeShelfAdd.tpl');

    }

    //编辑仓库货位
    function storeShelfEdit(){

        global $G_PGLOB;

        //实例化公共类
        $commHandler = new commHandler($G_PGLOB->DBCA);

        //接收仓库ID
        $storeID = isset($_REQUEST['storeID'])? $_REQUEST['storeID'] : '';
        $shelfID = isset($_REQUEST['shelfID'])? $_REQUEST['shelfID'] : '';

        //查询仓库信息
        $storeArr = array('storeID'=>$storeID);
        $storeInfo = $commHandler->search($storeArr,'wms_store');

        if( empty($storeInfo) ){
            $G_PGLOB->smarty->assign('msg','没有找到对应仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();
        }

        //查询信息是否存在
        $check = array('storeID'=>$storeID,'shelfID'=>$shelfID);
        $result = $commHandler->search($check,'wms_store_shelf');

        if( empty($result) ){
            $G_PGLOB->smarty->assign('msg','没有找到该货位信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();
        }

        //获取仓库列表
        $result_store = $G_PGLOB->DBCA->stmt_query('SELECT storeID,storeName FROM wms_store');

        $G_PGLOB->smarty->assign_by_ref('store_array',$result_store);
        $G_PGLOB->smarty->assign_by_ref('storeShelf',$result[0]);
        $G_PGLOB->smarty->assign('storeID',$storeID);
        $G_PGLOB->smarty->assign('shelfID',$shelfID);
        $G_PGLOB->smarty->display('wms/storeShelfAdd.tpl');

    }

    //批量添加库位
    private function shelfBatch(){

        global $G_PGLOB;

        //获取仓库列表
        $result_store = $G_PGLOB->DBCA->stmt_query('SELECT storeID,storeName FROM wms_store');

        $G_PGLOB->smarty->assign_by_ref('store_array',$result_store);
        $G_PGLOB->smarty->display('wms/storeShelfBatch.tpl');

    }

    //导出仓库货位信息
    function shelfExport(){

        global $G_PGLOB;

        //检查phpexcel类
        quanli_include('framework/phpExecl/PHPExcel.php');
        quanli_include('framework/phpExecl/PHPExcel/Writer/Excel2007.php');

        //实例excel类
        $objPHPExcel = new PHPExcel();

        /**
         * 设置excel的属性
         */
        //创建人
        $objPHPExcel->getProperties()->setCreator("$G_PGLOB->currentUserName");
        //最后修改人
        $objPHPExcel->getProperties()->setLastModifiedBy("$G_PGLOB->currentUserName");
        //标题
        $objPHPExcel->getProperties()->setTitle("导出仓库货位信息");
        //题目
        $objPHPExcel->getProperties()->setSubject("导出仓库货位信息");
        //描述
        $objPHPExcel->getProperties()->setDescription("导出仓库货位信息");
        /**
         * 设置excel的属性
         */

        /**
         * sheet
         */
        //设置当前的sheet
        $objPHPExcel->setActiveSheetIndex(0);
        //设置sheet的name
        $objPHPExcel->getActiveSheet()->setTitle('导出仓库货位信息');
        /**
         * sheet
         */

        //接收参数
        $storeID = isset($_REQUEST['v1'])?$_REQUEST['v1']:'';

        //查询SQL
        $search_sql = '';

        if( !empty($storeID) && $storeID != -1 )
            $search_sql = ' WHERE wss.storeID='.$storeID;

        //查询该仓库下的库位信息
        $storeShelf = 'SELECT * FROM wms_store_shelf wss INNER JOIN wms_store ws ON wss.storeID = ws.storeID ' . $search_sql;
        $result     = $G_PGLOB->DBCA->stmt_query($storeShelf);

        /**
         * 设置标题
         */
        $objPHPExcel->getActiveSheet()->setCellValue('A1', '库位名称');
        $objPHPExcel->getActiveSheet()->setCellValue('B1', '所属仓库');
        /**
         * 设置标题
         */

        /**
         * 添加数据
         */
        if ($result) {

            $i = 2;

            foreach($result as &$Info) {

                $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $Info->shelf_name);
                $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $Info->storeName);

                $i++;

            }

        }
        /**
         * 添加数据
         */

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);

        //文件名称
        $fileName = '导出仓库货位_' . date('YmdHis') . '.xlsx';

        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        header("Content-Type: application/force-download");
        header("Content-Disposition:inline;filename=$fileName");
        header("Content-Transfer-Encoding: binary");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        $objWriter->save('php://output');

    }

    //显示导入模板
    function shelfImport(){

        global $G_PGLOB;

        //获取仓库列表
        $result_store = $G_PGLOB->DBCA->stmt_query('SELECT storeID,storeName FROM wms_store');

        $G_PGLOB->smarty->assign('store_array',$result_store);
        $G_PGLOB->smarty->display('wms/storeShelfImport.tpl');

    }

    //导入仓库货位号
    private function importShelf(){

        global $G_PGLOB;

        //实例化公共类
        $commHandler = new commHandler( $G_PGLOB->DBCA );

        //检查phpexcel类
        quanli_include('framework/phpExecl/PHPExcel.php');
        quanli_include('framework/phpExecl/PHPExcel/Writer/Excel2007.php');

        //实例excel类
        $objPHPExcel = new PHPExcel();

        /**
         * 设置excel的属性
         */
        //创建人
        $objPHPExcel->getProperties()->setCreator("$G_PGLOB->currentUserName");
        //最后修改人
        $objPHPExcel->getProperties()->setLastModifiedBy("$G_PGLOB->currentUserName");
        //标题
        $objPHPExcel->getProperties()->setTitle("导入货位信息");
        //题目
        $objPHPExcel->getProperties()->setSubject("导入货位信息");
        //描述
        $objPHPExcel->getProperties()->setDescription("导入货位信息");
        /**
         * 设置excel的属性
         */

        /**
         * sheet
         */
        //设置当前的sheet
        $objPHPExcel->setActiveSheetIndex(0);
        //设置sheet的name
        $objPHPExcel->getActiveSheet()->setTitle('导入货位信息');
        /**
         * sheet
         */

        //接收参数
        $storeID = isset($_REQUEST['storeID'])?$_REQUEST['storeID']:'';

        if( empty($storeID) ){
            echo '<script>alert("参数错误")</script>';
            die();
        }

        //查询仓库信息
        $storeArr = array('storeID'=>$storeID);
        $storeInfo = $commHandler->search($storeArr,'wms_store');

        if( empty($storeInfo) ){
            echo '<script>alert("没有找到对应仓库信息")</script>';
            die();
        }

        ini_set('max_excution_time',1800);

        //获得唯一标识
        $guid = make_uuid();
        $keysDetailFile = G_APPLICATION_BASEPATH.'quanliadmin/app/wms/action/'.$guid.'.csv';
        if(! move_uploaded_file($_FILES['search_file']['tmp_name'],$keysDetailFile)){
            echo '<script>alert("上传文件失败")</script>';
            die();
        }

        //用于记录正确的数据
        $right_data = array();

        //用于打印错误信息的数组
        $print_data = array();

        //用于统计错误信息数
        $error_data = array();

        //记录错误信息
        $msg = array();

        //默认为第一行
        $row_num = 1;

        //记录错误信息
        $msg = '';

        //判断文件导入列数是否正确的标志
        $flg_check = 0;

        setlocale(LC_ALL,'zh_CN.gb18030');

        //以只读的方式打开文件
        $handle = fopen($keysDetailFile,'r');

        //指针读取文件,一行一行读取,一行作为一个数组,用数字索引获取每行的具体值
        while(!!$csvData = fgetcsv($handle)){

            //循环记录每次循环出现的错误行
            $str = '';
            $str_number = 0;

            if($row_num == 1){
                if(count($csvData) != 1){
                    $msg[] = '导入的CSV文件列数不正确，请检查后再导入';
                    $flg_check = 1;
                    break;
                }
            }

            if($row_num >1){

                $shelf_name  = trim($csvData[0]);


                if($shelf_name == ''){
                    $str .= '第'.$row_num.'列货位号为空';
                    $str_number++;
                }

                if($str_number != 0){
                    $error_data[] = $str;
                    $print_data[] = $shelf_name;
                }else{
                    $right_data[] = $shelf_name;
                }

            }
            $row_num++;
        }

        if($row_num > 1002){
            die('您导入的数据已超过1000条，请减少数据后再导入');
        }

        if($right_data){
            foreach ($right_data as $shelf_name){

               $shelfObj = new entity('wms_store_shelf');
               $shelfObj->storeID = $storeID;
               $shelfObj->shelf_name = $shelf_name;

                if( $G_PGLOB->DBCA->fetch($shelfObj) )
                    continue;

                $G_PGLOB->DBCA->save($shelfObj);

            }
        }

        //统计失败的条数
        $error_row = count($error_data);

        //统计成功导入的条数
        $right_row = $row_num-$error_row-2;

        if(!$flg_check){

            /**
             * 设置标题
             */
            $objPHPExcel->getActiveSheet()->setCellValue('A1', '导入成功条数');
            $objPHPExcel->getActiveSheet()->setCellValue('B1', '错误信息条数');
            $objPHPExcel->getActiveSheet()->setCellValue('A2', $right_row);
            $objPHPExcel->getActiveSheet()->setCellValue('B2', $error_row);
            $objPHPExcel->getActiveSheet()->setCellValue('A3', '错误信息');
            /**
             * 设置标题
             */

            /**
             * 添加数据
             */
            if ($error_data) {

                $i = 4;

                foreach($error_data as &$Info) {

                    $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $Info);

                    $i++;

                }

            }
            /**
             * 添加数据
             */

            $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(60);
            $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(60);

        }else{
            $objPHPExcel->getActiveSheet()->setCellValue('A1', '导入的CSV文件列数不正确，请检查后再导入');
            $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(80);
        }

        fclose($handle);

        ini_restore('max_execution_time');

        //文件名称
        $fileName = '导入货位_' . date('YmdHis') . '.xlsx';

        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        header("Content-Type: application/force-download");
        header("Content-Disposition:inline;filename=$fileName");
        header("Content-Transfer-Encoding: binary");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        $objWriter->save('php://output');

    }

    //货品上架
    function goodsUp(){

        global $G_PGLOB;

        //实例化公共类
        $commHandler = new commHandler($G_PGLOB->DBCA);

        //接收仓库ID
        $storeID = isset($_REQUEST['storeID'])? $_REQUEST['storeID'] : '';

        //查询仓库信息
        $storeArr = array('storeID'=>$storeID);
        $storeInfo = $commHandler->search($storeArr,'wms_store');

        if( empty($storeInfo) ){
            $G_PGLOB->smarty->assign('msg','没有找到对应仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();
        }

        $G_PGLOB->smarty->assign('storeName',$storeInfo[0]->storeName);
        $G_PGLOB->smarty->assign('storeID' , $storeID);
        $G_PGLOB->smarty->display('wms/storeGoodsUp.tpl');

    }

    //库位管理
    function shelfManage(){

        global $G_PGLOB;

        //实例化公共类
        $commHandler = new commHandler($G_PGLOB->DBCA);

        //接收仓库ID
        $storeID = isset($_REQUEST['storeID'])? $_REQUEST['storeID'] : '';

        //查询仓库信息
        $storeArr = array('storeID'=>$storeID);
        $storeInfo = $commHandler->search($storeArr,'wms_store');

        if( empty($storeInfo) ){
            $G_PGLOB->smarty->assign('msg','没有找到对应仓库信息');
            $G_PGLOB->smarty->display('comm/errorDisplay.tpl');
            die();
        }

        $G_PGLOB->smarty->assign('storeName',$storeInfo[0]->storeName);
        $G_PGLOB->smarty->assign('storeID' , $storeID);
        $G_PGLOB->smarty->display('wms/storeShelfManage.tpl');

    }

    //导出货位绑定信息
    function storeshelfExport(){

        global $G_PGLOB;

        //仓库类
        $wmsHandler = new wmsHandler($G_PGLOB->DBCA);

        //查询传参数组
        $params = array();

        //接收参数
        $storeID = $_REQUEST['v1'];
        $field   = $_REQUEST['v2'];
        $value   = $_REQUEST['v3'];

        if( $storeID != -1 )
            $params['storeID'] = $storeID;

        if( $field == 1 ){
            $params['shelf_name'] = $value;
        } else if ( $field == 2 ){
            $params['product_code'] = $value;
        } else if ( $field == 3 ){
            $params['goods_name'] = $value;
        }

        //查询
        $result = $wmsHandler->searchShelfGoods($params);

        //检查phpexcel类
        quanli_include('framework/phpExecl/PHPExcel.php');
        quanli_include('framework/phpExecl/PHPExcel/Writer/Excel2007.php');

        //实例excel类
        $objPHPExcel = new PHPExcel();

        /**
         * 设置excel的属性
         */
        //创建人
        $objPHPExcel->getProperties()->setCreator("$G_PGLOB->currentUserName");
        //最后修改人
        $objPHPExcel->getProperties()->setLastModifiedBy("$G_PGLOB->currentUserName");
        //标题
        $objPHPExcel->getProperties()->setTitle("导出货位绑定信息");
        //题目
        $objPHPExcel->getProperties()->setSubject("导出货位绑定信息");
        //描述
        $objPHPExcel->getProperties()->setDescription("导出货位绑定信息");
        /**
         * 设置excel的属性
         */

        /**
         * sheet
         */
        //设置当前的sheet
        $objPHPExcel->setActiveSheetIndex(0);
        //设置sheet的name
        $objPHPExcel->getActiveSheet()->setTitle('导出货位绑定信息');
        /**
         * sheet
         */

        /**
         * 设置标题
         */
        $objPHPExcel->getActiveSheet()->setCellValue('A1', '所在仓库');
        $objPHPExcel->getActiveSheet()->setCellValue('B1', '货位号');
        $objPHPExcel->getActiveSheet()->setCellValue('C1', '商品SKU');
        $objPHPExcel->getActiveSheet()->setCellValue('D1', '商品名称');
        /**
         * 设置标题
         */

        /**
         * 添加数据
         */
        if ($result) {

            $i = 2;

            foreach($result as &$Info) {

                $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $Info['storeName']);
                $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $Info['shelf_name']);
                $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $Info['product_code']);
                $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $Info['goods_name']);

                $i++;

            }

        }
        /**
         * 添加数据
         */

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(100);

        //文件名称
        $fileName = '导出货位绑定信息_' . date('YmdHis') . '.xlsx';

        $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
        header("Content-Type: application/force-download");
        header("Content-Disposition:inline;filename=$fileName");
        header("Content-Transfer-Encoding: binary");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        $objWriter->save('php://output');

    }

    /**
     * 日常管理
     */
    private function dailyManage(){
        global $G_PGLOB;

        if(!isset($_REQUEST['type']) || !is_numeric($_REQUEST['type']) || $_REQUEST['type'] > 3 || $_REQUEST['type'] < 1 ){
            $_REQUEST['type'] = 1;
        }

        //获取仓库列表
        $result_store = $G_PGLOB->DBCA->stmt_query('SELECT storeID,storeName FROM wms_store');
        $G_PGLOB->smarty->assign('store_array',$result_store);

        //货位列表编辑权限
        $G_PGLOB->smarty->assign( 'EDIT_STORESHELFLIST' , $G_PGLOB->has_permission(6010) );

        //货位整理编辑权限
        $G_PGLOB->smarty->assign( 'EDIT_STORESHELFMANAGE' , $G_PGLOB->has_permission(6011) );

        if($_REQUEST['type'] == 1){
            $G_PGLOB->smarty->display('wms/storeShelfList.tpl');
        }elseif($_REQUEST['type'] == 2){
            $G_PGLOB->smarty->display('wms/storeGoodsUp.tpl');
        }elseif($_REQUEST['type'] == 3){
            $G_PGLOB->smarty->display('wms/storeShelfManage.tpl');
        }

    }

}

